// pages/find/find.js
let leftHeight = 0,
  rightHeight = 0; //分别定义左右两边的高度
let query;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0, //距离顶部
    active: 0, //tab下标
    bgImg: [{
      url: '',
      img: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VNzuyT5jAx8bCtJj6aMmOFHXVkjXeGUIX7grl8Uy1yBe2WMtELOghbVfUTR9ZZ4KO*A!!/b&bo=HQTEAR0ExAEDCSw!&rf=viewer_4'
    }, {
      url: '',
      img: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VNzuyT5jAx8bCtJj6aMmOFHXVkjXeGUIX7grl8Uy1yBe2WMtELOghbVfUTR9ZZ4KO*A!!/b&bo=HQTEAR0ExAEDCSw!&rf=viewer_4'
    }, {
      url: '',
      img: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN9BFlVuls8I3UYHOTLJFc.mYyAhWl3r7p6hwyA.EaH9mUQvE9tm7OHsEm7AliSwz.Q!!/b&bo=HQQsAR0ELAEDCSw!&rf=viewer_4'
    }],
    cur: 0, //轮播激活

    // 瀑布流
    list: [{
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN2O7fvFa2KzqRbOZTIjy6iHqrjh3*4tKsN8aDq3BcfSSH8HZU6zSv5zonZsTwDpxbw!!/b&bo=GwOiAxsDogMDCSw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VNwceIz0z.X7WOhVdeDfE2ZegT1kC0lyh7fmNGr.9M0u.tg0.Ia1Q6YAAcGxxg0wVKQ!!/b&bo=PgFrAT4BawEDCSw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN919Jh8reORJIZpcPdEkN5PHwcEIo1403ptKRfsEezHxJ8TJ45PC7Qzq5TVY*hR13g!!/b&bo=*wD*AP8A*wADCSw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'

    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN9LSuDI7F6qvgjkb2ZAtRJ4aOZrWNqSUTL24Q3QxcxAp3vSQ8d*2kZmKEUyeuLXNLg!!/b&bo=CgEIAQoBCAEDCSw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMW8zDMWm3ttfK39ouqGuH09lDP1rX1m2uFvcDVA4.xq1LEwZhkeeyMXFKlxDGmv7wT8OFIVTM43Y5RyA6qaRXMU!/b&bo=CwRJAgsESQIDORw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN1U9KmGxetcPspc7SxUL6MWvRE9hR7EgDR7Ii88zhlSufeJr9wLJ2NZHZgVk.1wf7w!!/b&bo=IwEjASMBIwEDCSw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMfooLtNkULzlJi6McOIddOkFnah6bLp8l5vCSSZEbYZd*DzwlYUkhVo6DQeF9eNEiHdchEQjLIDu.tJrJh7hMvE!/b&bo=CwRJAgsESQIDORw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4',
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMfAG*sw0eZF.fHo92RPGsEqK5zJDXViFXvUxUZWzT8DQwmi*tFjWvDAmPidZ5yyZoihh3RqIFttPsxldC3FbhL8!/b&bo=CwQIBAsECAQDSWw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMcZBpblYXpORUvoyL60f.Bg7bmmsKfckiMGfMTJugTEA.Ml9TSWg.iWWQtJ8ZuGp4MJvoOrVaPbGwb8uz2KCAWQ!/b&bo=CwRJAgsESQIDSWw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMW8zDMWm3ttfK39ouqGuH09lDP1rX1m2uFvcDVA4.xq1LEwZhkeeyMXFKlxDGmv7wT8OFIVTM43Y5RyA6qaRXMU!/b&bo=CwRJAgsESQIDORw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMdhLFWyZHerkcdFPw30EfT0ehKUY2VNQXiM0OxCHuodI49OkB7JfUJ8eiH8wrnrXQ3oxBDFobdA7REYLm3cbuMg!/b&bo=PQHvAD0B7wADGTw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/OmVq1gFIObiZCCY30a7VN6a5J7RZMkiyJsPwIdTSOqxE33OQpW9D4ooWJ3t4Qfc7.E85JsjDsrSa2pAkeCp7Bg!!/b&bo=TgBOAE4ATgADCSw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMVD52*ivJPw.9LCAqH0qJ4nEy1m4qSekXZNnTUBCmjrgWRCup5g.Tqagj7opQRdIdrV2wv3N5eUCJOUMtr4*mQo!/b&bo=PQHvAD0B7wADGTw!&rf=viewer_4g',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }, {
      title: '北欧风小房子装修也很北欧风小房子装修也很...',
      url: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMW8zDMWm3ttfK39ouqGuH09lDP1rX1m2uFvcDVA4.xq1LEwZhkeeyMXFKlxDGmv7wT8OFIVTM43Y5RyA6qaRXMU!/b&bo=CwRJAgsESQIDORw!&rf=viewer_4',
      name: '飞翔的企鹅',
      watch: '12.6万',
      avtar: 'http://m.qpic.cn/psc?/V11Sie321T6lY9/LjNfElrpEt6hXz54k3bCMSqZuZyzNh*Ir.BphugCRZKeik09k8IqS4frc9QV5AY7FICLv*I7VpfyKJ4hBYyp21kYdDzJuiza1.lq00TezZI!/b&bo=aQBpAGkAaQADGTw!&rf=viewer_4'
    }],
    leftList: [],
    rightList: [],


  },


  // 轮播
  swiperChange: function (e) {
    this.setData({
      cur: e.detail.current
    })
  },
  //  右侧滚动触发
  bindscrollTop(event) {

  },
  //回到顶部
  goTop: function (e) { // 一键回到顶部
    console.log(1111);
    wx.pageScrollTo({
      scrollTop: 0,
      duration: 300
    })
  },
  // 发布动态 pages/find/releaseNews/releaseNews  
  releaseNews(e){
    wx.navigateTo({
      url: '/pages/find/releaseNews/releaseNews',
    })
  },
  // tab  切换
  onChangetab(event) {
    // console.log(event.detail.name);
    this.setData({
      active: event.detail.name
    })
  },

  // 瀑布流
  async isLeft() {
    const {
      list,
      leftList,
      rightList
    } = this.data;
    query = wx.createSelectorQuery();
    for (const item of list) {
      leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item); //判断两边高度，来觉得添加到那边
      await this.getBoxHeight(leftList, rightList);
    }
  },
  getBoxHeight(leftList, rightList) { //获取左右两边高度
    return new Promise((resolve, reject) => {
      this.setData({
        leftList,
        rightList
      }, () => {
        query.select('#left').boundingClientRect();
        query.select('#right').boundingClientRect();
        query.exec((res) => {
          leftHeight = res[0].height; //获取左边列表的高度
          rightHeight = res[1].height; //获取右边列表的高度
          resolve();
        });
      });
    })
  },
  //跳转
  navigateTo(e) {
    const data = e.currentTarget.dataset.data //跳转参数
    const path = e.currentTarget.dataset.path

    wx.navigateTo({
      url: path,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    that.isLeft();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})